<!DOCTYPE html>
<html>
  <head>
    <title>登录页面</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/cookie_util.js"></script>
  <script type="text/javascript">
   function checkLogin(){
    var username=$("#username").val().trim();
    var password=$("#password").val().trim();
     $.ajax({
    			  url:"http://localhost:8080/ChatByAjax/login.do",
    			  type:"post",
    			  dataType:"json",
    			  data:{"username":username,"password":password},
    			  success:function(result){
    			  
    			  for(var key in result){
    			   if(key==1){
    			   var uid=result[key];
    			   addCookie("uid",uid,2);
    			   window.location.href="main.html";
    			   }else{
    			    alert("用户名或者密码错误");
    			   }
    			  }  
}  
    				//if(result==1){
    				 // addCookie("uid",uid);
    				  //window.location.href="main.html";
    				//}else{
    				//alert("用户名或者密码错误");
    				//}
    			
    		  });
   }
  </script>
  <body>
   <h1>登录页面</h1>
   <hr>
   <form action="login.do" method="post"> 
     <input type="text" id="username" name="username" placeholder="用户名" required="required"/><br>
     <input type="password" id="password" name="password" placeholder="密码" required="required"/><br>
     <input type="button" id="sub" value="登录" onclick="checkLogin()">
   </form>
  </body>
</html>
